package windows

import "time"

type SildingWindows struct {
	Blocks     *BucketCircularArray
	block_size int
	interval   time.Duration
}

func NewSlidingWindows(block_size int, interval time.Duration, opts ...BucketOption) *SildingWindows {
	s := &SildingWindows{
		interval:   interval,
		block_size: block_size,
	}

	blocks := NewBucketCircularArray(block_size, interval, opts...)
	s.Blocks = blocks
	return s
}

func (w *SildingWindows) GetBlocks() *BucketCircularArray {
	return w.Blocks
}

func (w *SildingWindows) GetSlidingWindowsSum() int {
	return w.Blocks.Sum()
}

func (w *SildingWindows) GetSlidingWindowsAverage() int {
	return w.Blocks.Average()
}

func (w *SildingWindows) Incr() {
	w.Blocks.GetCurBlock().GetBucket().GetAdder().Incr()
}
